package org.zjvis.datascience.common.widget.vo;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import org.zjvis.datascience.common.vo.column.ColumnQueryVO;

import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

/**
 * @description 用于图表控件的 最大最小值 的包装类POJO
 * @date 2022-06-22
 */
@Data
public class WidgetMinMaxRequestVO extends WidgetRequestBaseVO {
    @NotNull(message = "please specify column names")
    private  List<String> colNames;

    @NotNull(message = "please specify column types")
    private List<Integer> types;

    public List<ColumnQueryVO> toColumnQueryVOs() {
        List<ColumnQueryVO> result = new ArrayList<>();
        if (this.colNames.size() != this.types.size()) {
            return new ArrayList<ColumnQueryVO>();
        }
        for (int i = 0; i < this.colNames.size(); i++) {
            ColumnQueryVO vo = new ColumnQueryVO();
            vo.setTaskId(this.dataId);
            vo.setTable(this.tableName);
            vo.setName(this.colNames.get(i));
            vo.setType(this.types.get(i));
            if (this.pageSize != null) {
                vo.setPageSize(this.pageSize);
            }
            if (this.curPage != null) {
                vo.setCurPage(this.curPage);
            }
            vo.setData(new JSONObject());
            vo.setFilter(new JSONArray());
            vo.setMode(1);
            vo.setSortType(1);
            vo.setSortVal("ASC");
            vo.setSearchFilter(new JSONArray());
            result.add(vo);
        }
        return result;
    }
}
